//define pins. Do not include Serial Prints or delays
#define irLedPin 6          // IR Led on this pin
#define halfPeriod 9 //found Experimentally



int irRead(int readPin, int triggerPin); //function prototype

void setup()
{
  pinMode(irLedPin, OUTPUT);
  Serial.begin(9600); 
}

void loop()
{  
  irRead(irLedPin); //display the results
}

/******************************************************************************
 * This function can be used with a panasonic pna4602m ir sensor
 * it returns a zero if something is detected by the sensor, and a 1 otherwise
 * The function bit bangs a 38.5khZ waveform to an IR led connected to the
 * triggerPin for 1 millisecond, and then reads the IR sensor pin to see if
 * the reflected IR has been detected
 ******************************************************************************/
int irRead(int triggerPin)
{
    digitalWrite(triggerPin, HIGH); 
    delayMicroseconds(halfPeriod);
    digitalWrite(triggerPin, LOW); 
    delayMicroseconds(halfPeriod-3);     // -3 to make up for digitaWrite overhead    
}
